package com.college.products.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.college.common.pojo.ao.Collection;
import com.college.common.pojo.dto.products.AddCollectionDTO;
import com.college.common.pojo.dto.products.QueryCollectionDTO;
import com.college.common.pojo.dto.products.UpdateCollectionDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.products.mapper.CollectionMapper;
import com.college.products.service.CollectionService;
import com.github.pagehelper.page.PageMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 收藏 服务实现类
 * @author 小C工作室
 * @since 2025-02-22
 */
@Service
public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collection> implements CollectionService {
    @Autowired
    private CollectionMapper collectionMapper;

    @Override
    public List<Collection> queryList(QueryCollectionDTO queryCollectionDTO) {
        return collectionMapper.queryList(queryCollectionDTO);
    }

    @Override
    public List<Collection> queryListPage(QueryCollectionDTO queryCollectionDTO, PageParamRequest pageParamRequest) {
        PageMethod.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return collectionMapper.queryList(queryCollectionDTO);
    }

    @Override
    public CommonResult<String> addCollection(AddCollectionDTO addCollectionDTO) {
        return this.save(addCollectionDTO)? CommonResult.success("收藏新增成功") : CommonResult.failed("收藏新增失败");
    }

    @Override
    public CommonResult<String> updateCollection(UpdateCollectionDTO updateCollectionDTO) {
        Collection collection = ObjectUtil.objectCopyProperties(updateCollectionDTO, Collection.class);
        return this.updateById(collection) ? CommonResult.success("收藏修改成功") : CommonResult.failed("收藏修改失败");
    }
}
